// pages/article/ArticleDetails.js
var Zan = require('../../dist/index');
var WxParse = require('../../wxParse/wxParse.js');
let WxNotificationCenter = require('../../utils/WxNotificationCenter.js');
let network = null;
let api = null;
let app = getApp();

Page(Object.assign({}, Zan.TopTips, {

  /**
   * 页面的初始数据
   */
  data: {
    articleId: '',
    title: '',
    createDate:'',
    readCount:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    network = new app.NetWorkUtils();
    api = new app.Api()
    console.log("生命周期函数--监听页面加载");
    console.log(options.articleId);
    network._post_json(this, api.getArticleDetail, { articleId: options.articleId }, success);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
}))

// 获取商品列表结果
var success = function (that, res) {
  if (res.data.data) {
    that.setData({
      title: res.data.data.title,
      createDate: res.data.data.createDate.substring(0,16),
      readCount: res.data.data.readCount,
      detail: res.data.data.detail.replace(/\<img/gi, '<img style="width:100%;height:auto" ').replace(/\white-space: nowrap;/gi, '').replace(/\white-space:nowrap;/gi, '')
    })
    // WxParse.wxParse('details', 'html', res.data.data.detail, that, 0);
    WxNotificationCenter.postNotificationName('articleRefreshNotification');
  }
}